package com.qk.util;

import cn.hutool.core.date.DateUtil;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Map;

/**
 * @Author: zhangchuang
 * @Date: 2025/10/11 14:02
 * @Description: JWT工具类
 */
@SuppressWarnings("all")
public class JWTUtils {

    private static final String JWT_SECRET = "ywencswml";
    private static final int EXPIRATION_DAYS = 7;
    public static final String KEY_ID = "id";
    public static final String KEY_USERNAME = "username";

    public static String createToken(Map<String,  Object>  claims) {
        return Jwts.builder()
                .setClaims(claims)
                .setExpiration(DateUtil.offsetDay(DateUtil.date(), EXPIRATION_DAYS))
                .signWith(SignatureAlgorithm.HS256, JWT_SECRET)
                .compact();
    }

    public static Map<String, Object> parseToken(String token) {
        return Jwts.parser()
                .setSigningKey(JWT_SECRET)
                .parseClaimsJws(token)
                .getBody();
    }

}
